//
//  UIView+Screen.m
//  Gafaer
//
//  Created by lanjue on 16/4/13.
//  Copyright © 2016年 lanjue. All rights reserved.
//

#import "UIView+Screen.h"

@implementation UIView (Screen)
//截取界面转化成图片
-(UIImage *)convertViewToImage
{
    
//    UIGraphicsBeginImageContext(self.bounds.size);
//    
//    [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES];
//    
//    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
//    
//    UIGraphicsEndImageContext();
//    
//    return image;
    // 创建一个context
    UIGraphicsBeginImageContextWithOptions(self.bounds.size, self.opaque, 0.0);
    
    //把当前的全部画面导入到栈顶context中并进行渲染
    [self.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    // 从当前context中创建一个新图片
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    
    return img;
}
@end
